<?php
	//Flat file DB based vfs for low volume sites and debuging
	require('benix/bin/server/vfs.php');
	//MySQL based vfs for advanced sites
	//require('benix/bin/server/mysql-vfs.php');	
$version = '0.1';

$username = $_GET["username"];
$password = $_GET["pass"];
$user_hash = $_GET["hash"];
$function_id = $_GET["function_id"];
$function_args = $_GET["args"];
$current_user;

function syscall($function_id,$args)
{
	if($_GET["hash"] == 6667)
		$current_user = "guest";
	
	if($_GET["hash"] == getUserHash($_GET["username"]) )
	{
		if($function_id == 01)
			return read( "./tmp_root/".$current_user."/fs_root".$_GET["path"],$_GET["function_flags"]);
		else if($function_id == 02)
			return write( "./tmp_root/".$current_user."/fs_root".$_GET["path"],$_GET["function_flags"],$_GET["function_buffer"]);
	}
};

function getUserHash($userName)
{
	return 6667;
};
	
function auth($username,$password)
{	
	if($username == "guest" && $password == "pass")
	{
		echo 6667;
	}
	else
		echo 'FAIL';
	return;
};

function read($path,$flags)
{
	if($flags == 0)
	{
		return 0;
	}
	else if($flags == 1)
	{
		vfs_lister($path);
		return 0;
	}
	else if($flags == 2)
	{
		vfs_lister($path);
		return 0;
	}
	else if($flags == 3 || $flags == 4)
	{
		echo vfs_read($path,$flags);
		return 0;		
	}
	else
	{
		echo "FAIL";
		return -1;
	}
};

function write($path,$flags,$buffer)
{
	if($flags == 0)
	{
		vfs_unlink($path);
	}
	else if($flags == 1)
	{
		vfs_createdir();
	}
	else if($flags == 2)
	{
		echo "create file ".$path;		
	}
	else if($flags == 3)
	{
		echo "create link file ".$path;		
	}
	else
	{
		echo "FAIL";
		return -1;
	}
};

if(!$user_hash)
	return( auth($username,$password) );
else
	return( syscall($function_id,$function_args ));

?>







